##########################################################################################
###  Replication code for:
###  Supporting Information for "Do Primaries Improve Electoral Performance? Clientelism
###  and Intra-Party Conflict in Ghana," American Journal of Political Science
###
###  IchinoNathan_AJPS_primariesSI_analysis.R
###
###  Nahomi Ichino and Noah Nathan
###  Department of Government, Harvard University
###  June 2012 
###
### 
###  Calls: 
###  IchinoNathan_primariesdata.csv  
###  beanplot_data_NDC.csv
###  beanplot_data_NPP.csv
###  matchingoutput.Rdata
###  matchingoutput_t3SI.Rdata
###  matchingoutput_t4SI.Rdata
###  matchingoutput_t56SI.Rdata
###  matchingoutput_t56SIc.Rdata
##########################################################################################


##########################################################################################
###  Table 1: Summary Statistics
##########################################################################################


library(foreign)
rm(list=ls())

## read in data and form subsets
data<-read.csv("IchinoNathan_primariesdata.csv")
data2a<-subset(data,data$party=="NDC")
data2b<-subset(data,data$party=="NPP")
data3<-na.omit(data$prim_elec)
data4<-subset(data,data$holds1==1)
data5<-subset(data2b, data2b$year==2008)
data6<-na.omit(data$incumbent)
data7<-na.omit(data2a$log_MPdist)


### (a) outcome variables 
win_election<-c(mean(data$winner_t), sd(data$winner_t), min(data$winner_t), max(data$winner_t), length(data$winner_t))
NDC_parl<-c(mean(data2a$vote_share_t), sd(data2a$vote_share_t), min(data2a$vote_share_t), max(data2a$vote_share_t), length(data2a$vote_share_t))
NPP_parl<-c(mean(data2b$vote_share_t), sd(data2b$vote_share_t), min(data2b$vote_share_t), max(data2b$vote_share_t), length(data2b$vote_share_t))
NDC_pres<-c(mean(data2b$ndc_pres_t), sd(data2b$ndc_pres_t), min(data2b$ndc_pres_t), max(data2b$ndc_pres_t), length(data2b$ndc_pres_t))
NPP_pres<-c(mean(data2b$npp_pres_t), sd(data2b$npp_pres_t), min(data2b$npp_pres_t), max(data2b$npp_pres_t), length(data2b$npp_pres_t))
turnout<-c(mean(data2b$turnout_t_pres), sd(data2b$turnout_t_pres), min(data2b$turnout_t_pres), max(data2b$turnout_t_pres), length(data2b$turnout_t_pres))

### (b) treatment/explanatory variable
primelec<-c(mean(data3), sd(data3), min(data3), max(data3), length(data3))

### (c) main matching variables
NDC_pres_t_1<-c(mean(data2a$ndc_pres_t_1), sd(data2a$ndc_pres_t_1), min(data2a$ndc_pres_t_1), max(data2a$ndc_pres_t_1), length(data2a$ndc_pres_t_1))
NPP_pres_t_1<-c(mean(data2a$npp_pres_t_1), sd(data2a$npp_pres_t_1), min(data2a$npp_pres_t_1), max(data2a$npp_pres_t_1), length(data2a$npp_pres_t_1))
ethfrac<-c(mean(data5$ethfrac), sd(data5$ethfrac), min(data5$ethfrac), max(data5$ethfrac), length(data5$ethfrac))
inc_seeking<-c(mean(data6), sd(data6), min(data6), max(data6), length(data6))
inc_belongs<-c(mean(data$holds1), sd(data$holds1), min(data$holds1), max(data$holds1), length(data$holds1))

### (d) additional matching variables
dist<-c(mean(data7), sd(data7), min(data7), max(data7), length(data7))
minister<-c(mean(data2a$min_inc_alt), sd(data2a$min_inc_alt), min(data2a$min_inc_alt), max(data2a$min_inc_alt), length(data2a$min_inc_alt))
dispute<-c(mean(data$dispute_before), sd(data$dispute_before), min(data$dispute_before), max(data$dispute_before), length(data$dispute_before))
urban<-c(mean(data2a$urban), sd(data2a$urban), min(data2a$urban), max(data2a$urban), length(data2a$urban)) 
public<-c(mean(data5$public_semipublic_p), sd(data5$public_semipublic_p), min(data5$public_semipublic_p), max(data5$public_semipublic_p), length(data5$public_semipublic_p))
english<-c(mean(data5$english_percent), sd(data5$english_percent), min(data5$english_percent), max(data5$english_percent), length(data5$english_percent))


### put it together
sumstat_table<-round(rbind(win_election, NDC_parl, NPP_parl, NDC_pres, NPP_pres, turnout, primelec, NDC_pres_t_1, NPP_pres_t_1, ethfrac, inc_seeking, inc_belongs, dist, minister, dispute, urban, public, english), digits=3)

sumstat_table


##########################################################################################
###  Figure 1: Beanplots
##########################################################################################

## install the package "beanplot" if necessary 
#install.packages("beanplot")

library(beanplot)
rm(list=ls())

data1 <- read.csv("beanplot_data_NPP.csv") 
data2 <- read.csv("beanplot_data_NDC.csv") 
 
data1.treated<-subset(data1, prim_elec>0)
data1.control<-subset(data1, prim_elec<1)
data2.treated<-subset(data2, prim_elec>0)
data2.control<-subset(data2, prim_elec<1)

## Panel (a) is party's vote share in presidential election for NDC and NPP
## Panel (b) is turnout in presidential election for NDC and NPP

pdf(file= "fig1_SI.pdf", width = 9, height = 8, family = "Helvetica", pointsize = 10)
par(mfrow=c(1,2))

# panel (a)
beanplot(data2$pres_t~data2$prim_elec, data1$pres_t~data1$prim_elec, names=c("NDC", "NPP"), side = "b", col = list("yellow", "orange"), border = c("yellow2", "darkorange"), beanlinewd=.5, ylab="(a) Party's Vote Share in Presidential Election", ylim=c(0,1), cex=1, xlab="NDC Primary                       NPP Primary", xaxt="n", main="(a)")
axis(1, at=c(0.8, 1.2, 1.8, 2.2), labels=c("No", "Yes", "No", "Yes"))

# panel (b)
beanplot(data2$turnout_t_pres ~data2$prim_elec, data1$turnout_t_pres~data1$prim_elec, names=c("NDC", "NPP"), side = "b", col = list("yellow", "orange"), border = c("yellow2", "darkorange"), beanlinewd=.5, ylab="(b) Turnout", ylim=c(0.3,1), xlab="NDC Primary                       NPP Primary", xaxt="n", main="(b)")
axis(1, at=c(0.8, 1.2, 1.8, 2.2), labels=c("No", "Yes", "No", "Yes"))

legend("bottomright", bty="n",c("No primary election", "Primary election"),fill = c("yellow", "orange"), cex=1.3)
dev.off()


##########################################################################################
###  Figures 2 and 3: Balance Plots
##########################################################################################

## install the package "Matching" if necessary 
#install.packages("Matching")
library(Matching)
rm(list=ls())

load("matchingoutput.Rdata")


############################
### NDC 
x<-cbind(data2$year2008, data2$incumbent, data2$holds1, data2$ethfrac, data2$pres_t_1)
row.number <- c()
treated.NDC <- matrix(NA, nrow=nrow(genout.2.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.2.ATE$matches)){
	row.number[i] <- genout.2.ATE$matches[i,1]
	treated.NDC <- x[row.number,]
	}
row.number <- c()
controls.NDC <- matrix(NA, nrow=nrow(genout.2.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.2.ATE$matches)){
	row.number[i] <- genout.2.ATE$matches[i,2]
	controls.NDC <- x[row.number,]
	}


############################
### NPP 
x<-cbind(data1$year2008, data1$incumbent, data1$holds1, data1$ethfrac, data1$pres_t_1)
row.number <- c()
treated.NPP <- matrix(NA, nrow=nrow(genout.1.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.1.ATE$matches)){
	row.number[i] <- genout.1.ATE$matches[i,1]
	treated.NPP <- x[row.number,]
	}

row.number <- c()
controls.NPP <- matrix(NA, nrow=nrow(genout.1.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.1.ATE$matches)){
	row.number[i] <- genout.1.ATE$matches[i,2]
	controls.NPP <- x[row.number,]
	}

############################
### COMPETITIVE NPP
x<-cbind(data.cnpp$year2008, data.cnpp$incumbent, data.cnpp$holds1, data.cnpp$ethfrac, data.cnpp$pres_t_1)
row.number <- c()
treated.NPP.comp <- matrix(NA, nrow=nrow(genout.cnpp.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.cnpp.ATE$matches)){
	row.number[i] <- genout.cnpp.ATE$matches[i,1]
	treated.NPP.comp <- x[row.number,]
	}
row.number <- c()
controls.NPP.comp <- matrix(NA, nrow=nrow(genout.cnpp.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.cnpp.ATE$matches)){
	row.number[i] <- genout.cnpp.ATE$matches[i,2]
	controls.NPP.comp <- x[row.number,]
	}


############################
### STRONGHOLD NPP
x<-cbind(data.nnpp$year2008, data.nnpp$incumbent, data.nnpp$holds1, data.nnpp$ethfrac, data.nnpp$pres_t_1)
row.number <- c()
treated.NPP.ncomp <- matrix(NA, nrow=nrow(genout.nnpp.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.nnpp.ATE$matches)){
	row.number[i] <- genout.nnpp.ATE$matches[i,1]
	treated.NPP.ncomp <- x[row.number,]
	}
row.number <- c()
controls.NPP.ncomp <- matrix(NA, nrow=nrow(genout.cnpp.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.nnpp.ATE$matches)){
	row.number[i] <- genout.nnpp.ATE$matches[i,2]
	controls.NPP.ncomp <- x[row.number,]
	}

## figure 2:
pdf(file= "fig2_SI.pdf", width = 7, height = 5, family = "Helvetica", pointsize = 10)
par(mfrow=c(2,2))

qqplot(controls.NDC[,4], treated.NDC[,4], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (ND)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)
	
qqplot(controls.NDC[,5], treated.NDC[,5], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last pres. election (NDC)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

qqplot(controls.NPP[,4], treated.NPP[,4], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NPP)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)
	
qqplot(controls.NPP[,5], treated.NPP[,5], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last pres. election (NPP)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

dev.off()

## figure 3:
pdf(file= "fig3_SI.pdf", width = 7, height = 5, family = "Helvetica", pointsize = 10)
par(mfrow=c(2,2))

qqplot(controls.NPP.comp[,4], treated.NPP.comp[,4], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NPP Competitive)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)
	
qqplot(controls.NPP.comp[,5], treated.NPP.comp[,5], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last pres. election (NPP Competitive)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

qqplot(controls.NPP.ncomp[,4], treated.NPP.ncomp[,4], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NPP Stronghold)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)
	
qqplot(controls.NPP.ncomp[,5], treated.NPP.ncomp[,5], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last pres. election (NPP Stronghold)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)


dev.off()


##########################################################################################
###  Table 2: NDC
##########################################################################################

### This is just reproduction of results from Table 1 panel (a) and Table 2 panel (a) in 
### the article.

##########################################################################################
###  Figure 4: NDC Subsets Balance Plots
##########################################################################################

library(Matching)
rm(list=ls())

load("matchingoutput_t3SI.Rdata")

#### NDC Competitive


x<-cbind(data2$year2008, data2$incumbent, data2$holds1, data2$ethfrac, data2$pres_t_1)

row.number <- c()
treated.NDC <- matrix(NA, nrow=nrow(genout.2.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.2.ATE$matches)){
	row.number[i] <- genout.2.ATE$matches[i,1]
	treated.NDC <- x[row.number,]
	}

row.number <- c()
controls.NDC <- matrix(NA, nrow=nrow(genout.2.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.2.ATE$matches)){
	row.number[i] <- genout.2.ATE$matches[i,2]
	controls.NDC <- x[row.number,]
	}


#### NDC STRONGHOLD

x<-cbind(data2a$year2008, data2a$incumbent, data2a$holds1, data2a$ethfrac, data2a$pres_t_1)

row.number <- c()
treated.NNDC <- matrix(NA, nrow=nrow(genout.2a.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.2a.ATE$matches)){
	row.number[i] <- genout.2a.ATE$matches[i,1]
	treated.NNDC <- x[row.number,]
	}

row.number <- c()
controls.NNDC <- matrix(NA, nrow=nrow(genout.2a.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.2a.ATE$matches)){
	row.number[i] <- genout.2a.ATE$matches[i,2]
	controls.NNDC <- x[row.number,]
	}


pdf(file= "fig4_SI.pdf", width = 10, height =6, family = "Helvetica", pointsize = 10)
par(mfrow=c(2,2))

qqplot(controls.NDC[,4], treated.NDC[,4], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NDC Comp ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)
	
qqplot(controls.NDC[,5], treated.NDC[,5], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last pres. election (NDC Comp ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

qqplot(controls.NNDC[,4], treated.NNDC[,4], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NDC Stronghold ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)
	
qqplot(controls.NNDC[,5], treated.NNDC[,5], plot.it=TRUE, xlab="No Primary", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last pres. election (NDC Stronghold ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

dev.off()


##########################################################################################
###  SI Table 3: NDC Subsets
##########################################################################################

library(Matching)
rm(list=ls())

ev<-c(FALSE,FALSE,TRUE,TRUE,TRUE)
ev.ndc<-c(FALSE,FALSE,TRUE,TRUE,TRUE)
load("matchingoutput_t3SI.Rdata")

##########################################
## NDC COMPETITIVE ONLY (OLS)

NDC.1 <- lm(data2$winner_t ~ data2$prim_elec+data2$pres_t_1+data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
NDC.2 <- lm(data2$vote_share_t_other ~ data2$prim_elec+data2$pres_t_1+data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
NDC.3 <- lm(data2$vote_share_t ~ data2$prim_elec+data2$pres_t_1+data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
NDC.4 <- lm(data2$pres_t ~ data2$prim_elec+data2$pres_t_1+data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
NDC.5 <- lm(data2$turnout_t_pres ~ data2$prim_elec+data2$pres_t_1+data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
round(summary(NDC.1)$coefficients[2,], digits=4)
round(summary(NDC.2)$coefficients[2,], digits=4)
round(summary(NDC.3)$coefficients[2,], digits=4)
round(summary(NDC.4)$coefficients[2,], digits=4)
round(summary(NDC.5)$coefficients[2,], digits=4)


##########################################
## NDC COMPETITIVE ONLY (ATE)

x<-cbind(data2$pres_t_1, data2$ethfrac, data2$year2008, data2$holds1, data2$incumbent)
mout.1<-Match(Y=data2$winner_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.2<-Match(Y=data2$vote_share_t_other, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.3<-Match(Y=data2$vote_share_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.4<-Match(Y=data2$pres_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.5<-Match(Y=data2$turnout_t_pres, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)

##########################################
## NDC COMPETITIVE ONLY (ATT)

x<-cbind(data2$pres_t_1, data2$ethfrac, data2$year2008, data2$holds1, data2$incumbent)
mout.1<-Match(Y=data2$winner_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.2<-Match(Y=data2$vote_share_t_other, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.3<-Match(Y=data2$vote_share_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.4<-Match(Y=data2$pres_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.5<-Match(Y=data2$turnout_t_pres, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


##########################################
## NDC STRONGHOLD ONLY (OLS)

NNDC1 <- lm(data2a$winner_t ~ data2a$prim_elec+data2a$pres_t_1+data2a$year2008+data2a$ethfrac+data2a$holds1+data2a$incumbent)
NNDC2 <- lm(data2a$vote_share_t_other ~ data2a$prim_elec+data2a$pres_t_1+data2a$year2008+data2a$ethfrac+data2a$holds1+data2a$incumbent)
NNDC3 <- lm(data2a$vote_share_t ~ data2a$prim_elec+data2a$pres_t_1+data2a$year2008+data2a$ethfrac+data2a$holds1+data2a$incumbent)
NNDC4 <- lm(data2a$pres_t ~ data2a$prim_elec+data2a$pres_t_1+data2a$year2008+data2a$ethfrac+data2a$holds1+data2a$incumbent)
NNDC5 <- lm(data2a$turnout_t_pres ~ data2a$prim_elec+data2a$pres_t_1+data2a$year2008+data2a$ethfrac+data2a$holds1+data2a$incumbent)

round(summary(NNDC1)$coefficients[2,], digits=4)
round(summary(NNDC2)$coefficients[2,], digits=4)
round(summary(NNDC3)$coefficients[2,], digits=4)
round(summary(NNDC4)$coefficients[2,], digits=4)
round(summary(NNDC5)$coefficients[2,], digits=4)

##########################################
## NDC STRONGHOLD ONLY (ATE)

x<-cbind(data2a$pres_t_1, data2a$ethfrac, data2a$year2008, data2a$holds1, data2a$incumbent)
mout.1<-Match(Y=data2a$winner_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
mout.2<-Match(Y=data2a$vote_share_t_other, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
mout.3<-Match(Y=data2a$vote_share_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
mout.4<-Match(Y=data2a$pres_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
mout.5<-Match(Y=data2a$turnout_t_pres, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


##########################################
## NDC STRONGHOLD ONLY (ATT)

x<-cbind(data2a$pres_t_1, data2a$ethfrac, data2a$year2008, data2a$holds1, data2a$incumbent)
mout.1<-Match(Y=data2a$winner_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
mout.2<-Match(Y=data2a$vote_share_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
mout.3<-Match(Y=data2a$vote_share_t_other, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
mout.4<-Match(Y=data2a$pres_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
mout.5<-Match(Y=data2a$turnout_t_pres, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)



##########################################################################################
###  Figure 5: Balance Plots Using Previous Parliamentary Vote Share
##########################################################################################


rm(list=ls())
load("matchingoutput_t4SI.Rdata")
	
x<-cbind(data2$vote_share_t_1, data2$ethfrac, data2$year2008, data2$holds1, data2$incumbent)

row.number <- c()
treated.NDC <- matrix(NA, nrow=nrow(genout.NDC.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.NDC.ATE$matches)){
	row.number[i] <- genout.NDC.ATE$matches[i,1]
	treated.NDC <- x[row.number,]
	}

row.number <- c()
controls.NDC <- matrix(NA, nrow=nrow(genout.NDC.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.NDC.ATE$matches)){
	row.number[i] <- genout.NDC.ATE$matches[i,2]
	controls.NDC <- x[row.number,]
	}


############################
### NPP 

x<-cbind(data1$vote_share_t_1, data1$ethfrac, data1$year2008, data1$holds1, data1$incumbent)

row.number <- c()
treated.NPP <- matrix(NA, nrow=nrow(genout.NPP.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.NPP.ATE$matches)){
	row.number[i] <- genout.NPP.ATE$matches[i,1]
	treated.NPP <- x[row.number,]
	}

row.number <- c()
controls.NPP <- matrix(NA, nrow=nrow(genout.NPP.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.NPP.ATE$matches)){
	row.number[i] <- genout.NPP.ATE$matches[i,2]
	controls.NPP <- x[row.number,]
	}

############################
### Competitive NPP

x<-cbind(data.CNPP$vote_share_t_1, data.CNPP$ethfrac, data.CNPP$year2008, data.CNPP$holds1, data.CNPP$incumbent)

row.number <- c()
treated.CNPP.comp <- matrix(NA, nrow=nrow(genout.CNPP.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.CNPP.ATE $matches)){
	row.number[i] <- genout.CNPP.ATE $matches[i,1]
	treated.CNPP.comp <- x[row.number,]
	}

row.number <- c()
controls.CNPP.comp <- matrix(NA, nrow=nrow(genout.CNPP.ATE $matches), ncol=ncol(x))
for(i in 1:nrow(genout.CNPP.ATE $matches)){
	row.number[i] <- genout.CNPP.ATE $matches[i,2]
	controls.CNPP.comp <- x[row.number,]
	}



########################
### Stronghold NPP

x<-cbind(data.NNPP$vote_share_t_1, data.NNPP$ethfrac, data.NNPP$year2008, data.NNPP$holds1, data.NNPP$incumbent)

row.number <- c()
treated.NNPP.ncomp <- matrix(NA, nrow=nrow(genout.NNPP.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.NNPP.ATE$matches)){
	row.number[i] <- genout.NNPP.ATE$matches[i,1]
	treated.NNPP.ncomp <- x[row.number,]
	}

row.number <- c()
controls.NNPP.ncomp <- matrix(NA, nrow=nrow(genout.NNPP.ATE$matches), ncol=ncol(x))
for(i in 1:nrow(genout.NNPP.ATE$matches)){
	row.number[i] <- genout.NNPP.ATE$matches[i,2]
	controls.NNPP.ncomp <- x[row.number,]
	}


pdf(file= "fig5_SI.pdf", width = 7, height = 9, family = "Helvetica", pointsize = 10)
par(mfrow=c(4,2))


qqplot(controls.NDC[,1], treated.NDC[,1], plot.it=TRUE, xlab="No Primary (Matched)", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last parl. election (NDC ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)
	
qqplot(controls.NDC[,2], treated.NDC[,2], plot.it=TRUE, xlab="No Primary (Matched)", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NDC ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

qqplot(controls.NPP[,1], treated.NPP[,1], plot.it=TRUE, xlab="No Primary (Matched)", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last parl. election (NPP ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

qqplot(controls.NPP[,2], treated.NPP[,2], plot.it=TRUE, xlab="No Primary (Matched)", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NPP ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)


qqplot(controls.CNPP.comp[,1], treated.CNPP.comp[,1], plot.it=TRUE, xlab="No Primary (Matched)", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last parl. election (NPP Comp ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)
	
qqplot(controls.CNPP.comp[,2], treated.CNPP.comp[,2], plot.it=TRUE, xlab="No Primary (Matched)", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NPP Comp ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

qqplot(controls.NNPP.ncomp[,1], treated.NNPP.ncomp[,1], plot.it=TRUE, xlab="No Primary (Matched)", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="% Vote in last parl. election (NPP Stronghold ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)

qqplot(controls.NNPP.ncomp[,2], treated.NNPP.ncomp[,2], plot.it=TRUE, xlab="No Primary (Matched)", ylab="Primary", col="dodgerblue4", pch=19, cex=1, ylim=c(0,1), xlim=c(0,1), main="Ethnic Fractionalization (NPP Stronghold ATE)")
abline(a=0, b=1, col="firebrick", lty="dashed", lwd=1.3)


dev.off()

	
	
##########################################################################################
###  Table 4: Using Previous Parliamentary Vote Share
##########################################################################################

## match on previous parliamentary vote share (excluding those with vote share=0) 
## rather than previous presidential vote share

library(Matching)
rm(list=ls())

ev<-c(FALSE,FALSE,TRUE,TRUE,TRUE)
ev.ndc<-c(FALSE,FALSE,TRUE,TRUE,TRUE)
load("matchingoutput_t4SI.Rdata")


#####################
## NDC (OLS)
#####################

NDC.1 <- lm(data2$winner_t ~ data2$prim_elec+data2$vote_share_t_1 +data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
NDC.2 <- lm(data2$vote_share_t_other ~ data2$prim_elec+data2$vote_share_t_1 +data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
NDC.3 <- lm(data2$vote_share_t ~ data2$prim_elec+data2$vote_share_t_1 +data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
NDC.4 <- lm(data2$pres_t ~ data2$prim_elec+data2$vote_share_t_1 +data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
NDC.5 <- lm(data2$turnout_t_pres ~ data2$prim_elec+data2$vote_share_t_1 +data2$year2008+data2$ethfrac+data2$holds1+data2$incumbent)
round(summary(NDC.1)$coefficients[2,], digits=4)
round(summary(NDC.2)$coefficients[2,], digits=4)
round(summary(NDC.3)$coefficients[2,], digits=4)
round(summary(NDC.4)$coefficients[2,], digits=4)
round(summary(NDC.5)$coefficients[2,], digits=4)

#####################
## NDC (ATE)
#####################

x<-cbind(data2$vote_share_t_1, data2$ethfrac, data2$year2008, data2$holds1, data2$incumbent)

mout.1<-Match(Y=data2$winner_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.NDC.ATE)
mout.2<-Match(Y=data2$vote_share_t_other, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.NDC.ATE)
mout.3<-Match(Y=data2$vote_share_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.NDC.ATE)
mout.4<-Match(Y=data2$pres_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.NDC.ATE)
mout.5<-Match(Y=data2$turnout_t_pres, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.NDC.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


#####################
## NDC (ATT)
#####################

x<-cbind(data2$vote_share_t_1, data2$ethfrac, data2$year2008, data2$holds1, data2$incumbent)
mout.1<-Match(Y=data2$winner_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.NDC.ATT)
mout.2<-Match(Y=data2$vote_share_t_other, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.NDC.ATT)
mout.3<-Match(Y=data2$vote_share_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.NDC.ATT)
mout.4<-Match(Y=data2$pres_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.NDC.ATT)
mout.5<-Match(Y=data2$turnout_t_pres, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.NDC.ATT)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


#####################
## NPP (OLS)
#####################

NPP.1 <- lm(data1$winner_t ~ data1$prim_elec+data1$vote_share_t_1 +data1$year2008+data1$ethfrac+data1$holds1+data1$incumbent)
NPP.2 <- lm(data1$vote_share_t ~ data1$prim_elec+data1$vote_share_t_1 +data1$year2008+data1$ethfrac+data1$holds1+data1$incumbent)
NPP.3 <- lm(data1$vote_share_t_other ~ data1$prim_elec+data1$vote_share_t_1 +data1$year2008+data1$ethfrac+data1$holds1+data1$incumbent)
NPP.4 <- lm(data1$pres_t ~ data1$prim_elec+data1$vote_share_t_1 +data1$year2008+data1$ethfrac+data1$holds1+data1$incumbent)
NPP.5 <- lm(data1$turnout_t_pres ~ data1$prim_elec+data1$vote_share_t_1 +data1$year2008+data1$ethfrac+data1$holds1+data1$incumbent)

round(summary(NPP.1)$coefficients[2,], digits=4)
round(summary(NPP.2)$coefficients[2,], digits=4)
round(summary(NPP.3)$coefficients[2,], digits=4)
round(summary(NPP.4)$coefficients[2,], digits=4)
round(summary(NPP.5)$coefficients[2,], digits=4)

#####################
## NPP (ATE)
#####################

x<-cbind(data1$vote_share_t_1, data1$ethfrac, data1$year2008, data1$holds1, data1$incumbent)
mout.1<-Match(Y=data1$winner_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NPP.ATE)
mout.2<-Match(Y=data1$vote_share_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NPP.ATE)
mout.3<-Match(Y=data1$vote_share_t_other, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NPP.ATE)
mout.4<-Match(Y=data1$pres_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NPP.ATE)
mout.5<-Match(Y=data1$turnout_t_pres, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NPP.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


#####################
## NPP (ATT)
#####################

x<-cbind(data1$vote_share_t_1, data1$ethfrac, data1$year2008, data1$holds1, data1$incumbent)
mout.1<-Match(Y=data1$winner_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NPP.ATT)
mout.2<-Match(Y=data1$vote_share_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NPP.ATT)
mout.3<-Match(Y=data1$vote_share_t_other, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NPP.ATT)
mout.4<-Match(Y=data1$pres_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NPP.ATT)
mout.5<-Match(Y=data1$turnout_t_pres, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NPP.ATT)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


###########################
## NPP competitive (OLS)
###########################

CNPP.1 <- lm(data.CNPP$winner_t ~ data.CNPP$prim_elec+data.CNPP$vote_share_t_1 +data.CNPP$year2008+data.CNPP$ethfrac+data.CNPP$holds1+data.CNPP$incumbent)
CNPP.2 <- lm(data.CNPP$vote_share_t ~ data.CNPP$prim_elec+data.CNPP$vote_share_t_1 +data.CNPP$year2008+data.CNPP$ethfrac+data.CNPP$holds1+data.CNPP$incumbent)
CNPP.3 <- lm(data.CNPP$vote_share_t_other ~ data.CNPP$prim_elec+data.CNPP$vote_share_t_1 +data.CNPP$year2008+data.CNPP$ethfrac+data.CNPP$holds1+data.CNPP$incumbent)
CNPP.4 <- lm(data.CNPP$pres_t ~ data.CNPP$prim_elec+data.CNPP$vote_share_t_1 +data.CNPP$year2008+data.CNPP$ethfrac+data.CNPP$holds1+data.CNPP$incumbent)
CNPP.5 <- lm(data.CNPP$turnout_t_pres ~ data.CNPP$prim_elec+data.CNPP$vote_share_t_1 +data.CNPP$year2008+data.CNPP$ethfrac+data.CNPP$holds1+data.CNPP$incumbent)

round(summary(CNPP.1)$coefficients[2,], digits=4)
round(summary(CNPP.2)$coefficients[2,], digits=4)
round(summary(CNPP.3)$coefficients[2,], digits=4)
round(summary(CNPP.4)$coefficients[2,], digits=4)
round(summary(CNPP.5)$coefficients[2,], digits=4)

##########################################
## NPP competitive (ATE)
##########################################

x<-cbind(data.CNPP$vote_share_t_1, data.CNPP$ethfrac, data.CNPP$year2008, data.CNPP$holds1, data.CNPP$incumbent)
mout.1<-Match(Y=data.CNPP$winner_t, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.CNPP.ATE)
mout.2<-Match(Y=data.CNPP$vote_share_t, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.CNPP.ATE)
mout.3<-Match(Y=data.CNPP$vote_share_t_other, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.CNPP.ATE)
mout.4<-Match(Y=data.CNPP$pres_t, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.CNPP.ATE)
mout.5<-Match(Y=data.CNPP$turnout_t_pres, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.CNPP.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


##########################################
## NPP competitive (ATT)
##########################################

x<-cbind(data.CNPP$vote_share_t_1, data.CNPP$ethfrac, data.CNPP$year2008, data.CNPP$holds1, data.CNPP$incumbent)
mout.1<-Match(Y=data.CNPP$winner_t, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.CNPP.ATT)
mout.2<-Match(Y=data.CNPP$vote_share_t, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.CNPP.ATT)
mout.3<-Match(Y=data.CNPP$vote_share_t_other, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.CNPP.ATT)
mout.4<-Match(Y=data.CNPP$pres_t, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.CNPP.ATT)
mout.5<-Match(Y=data.CNPP$turnout_t_pres, Tr=data.CNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.CNPP.ATT)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


###########################
## NPP Stronghold (OLS)
###########################

NNPP.1 <- lm(data.NNPP$winner_t ~ data.NNPP$prim_elec+data.NNPP$vote_share_t_1 +data.NNPP$year2008+data.NNPP$ethfrac+data.NNPP$holds1+data.NNPP$incumbent)
NNPP.2 <- lm(data.NNPP$vote_share_t ~ data.NNPP$prim_elec+data.NNPP$vote_share_t_1 +data.NNPP$year2008+data.NNPP$ethfrac+data.NNPP$holds1+data.NNPP$incumbent)
NNPP.3 <- lm(data.NNPP$vote_share_t_other ~ data.NNPP$prim_elec+data.NNPP$vote_share_t_1 +data.NNPP$year2008+data.NNPP$ethfrac+data.NNPP$holds1+data.NNPP$incumbent)
NNPP.4 <- lm(data.NNPP$pres_t ~ data.NNPP$prim_elec+data.NNPP$vote_share_t_1 +data.NNPP$year2008+data.NNPP$ethfrac+data.NNPP$holds1+data.NNPP$incumbent)
NNPP.5 <- lm(data.NNPP$turnout_t_pres ~ data.NNPP$prim_elec+data.NNPP$vote_share_t_1 +data.NNPP$year2008+data.NNPP$ethfrac+data.NNPP$holds1+data.NNPP$incumbent)
round(summary(NNPP.1)$coefficients[2,], digits=4)
round(summary(NNPP.2)$coefficients[2,], digits=4)
round(summary(NNPP.3)$coefficients[2,], digits=4)
round(summary(NNPP.4)$coefficients[2,], digits=4)
round(summary(NNPP.5)$coefficients[2,], digits=4)

##########################################
## NPP Stronghold (ATE)
##########################################

x<-cbind(data.NNPP$vote_share_t_1, data.NNPP$ethfrac, data.NNPP$year2008, data.NNPP$holds1, data.NNPP$incumbent)
mout.1<-Match(Y=data.NNPP$winner_t, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NNPP.ATE)
mout.2<-Match(Y=data.NNPP$vote_share_t, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NNPP.ATE)
mout.3<-Match(Y=data.NNPP$vote_share_t_other, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NNPP.ATE)
mout.4<-Match(Y=data.NNPP$pres_t, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NNPP.ATE)
mout.5<-Match(Y=data.NNPP$turnout_t_pres, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATE", exact= ev, Weight.matrix=genout.NNPP.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


##########################################
## NPP Stronghold (ATT)
##########################################

## matching variables
x<-cbind(data.NNPP$vote_share_t_1, data.NNPP$ethfrac, data.NNPP$year2008, data.NNPP$holds1, data.NNPP$incumbent)
mout.1<-Match(Y=data.NNPP$winner_t, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NNPP.ATT)
mout.2<-Match(Y=data.NNPP$vote_share_t, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NNPP.ATT)
mout.3<-Match(Y=data.NNPP$vote_share_t_other, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NNPP.ATT)
mout.4<-Match(Y=data.NNPP$pres_t, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NNPP.ATT)
mout.5<-Match(Y=data.NNPP$turnout_t_pres, Tr=data.NNPP$prim_elec, X=x, M=1, estimand="ATT", exact= ev, Weight.matrix=genout.NNPP.ATT)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
lm4<-lm(mout.4$mdata$Y~mout.4$mdata$Tr+mout.4$mdata$X)
lm5<-lm(mout.5$mdata$Y~mout.5$mdata$Tr+mout.5$mdata$X)

round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)
round(summary(lm4)$coefficients[2,], digits=4)
round(summary(lm5)$coefficients[2,], digits=4)


###########################################################################################
###  Table 5 (Panels A and B): Effect on Parliamentary Elections Results Using Additional Matching Variables
###########################################################################################


rm(list=ls())

library(Matching)
ev.ndc<-c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE)
ev<-c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE)

load("matchingoutput_t56SI.Rdata")


################################################################
## NDC only (OLS)

NDC.1 <- lm(data2$winner_t ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
NDC.2 <- lm(data2$vote_share_t_other ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
NDC.3 <- lm(data2$vote_share_t ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)

round(summary(NDC.1)$coefficients[2,], digits=4)
round(summary(NDC.2)$coefficients[2,], digits=4)
round(summary(NDC.3)$coefficients[2,], digits=4)

################################################################
## NDC only (ATE)

x<-cbind(data2$pres_t_1, data2$english_percent, data2$urban, data2$year2008, data2$ethfrac, data2$public_semipublic_p, data2$dispute_before, data2$holds1, data2$log_MPdist, data2$prim_other_total, data2$incumbent)

mout.1<-Match(Y=data2$winner_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.2<-Match(Y=data2$vote_share_t_other, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.3<-Match(Y=data2$vote_share_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)

################################################################
## NDC only (ATT)
x<-cbind(data2$pres_t_1, data2$english_percent, data2$urban, data2$year2008, data2$ethfrac, data2$public_semipublic_p, data2$dispute_before, data2$holds1, data2$log_MPdist, data2$prim_other_total, data2$incumbent)

mout.1<-Match(Y=data2$winner_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.2<-Match(Y=data2$vote_share_t_other, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.3<-Match(Y=data2$vote_share_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)

################################################################
## NPP only (OLS)

NPP.1 <- lm(data1$winner_t ~ data1$prim_elec+ data1$pres_t_1+ data1$english_percent+ data1$urban+ data1$year2008+ data1$ethfrac+ data1$public_semipublic_p+ data1$dispute_before+ data1$holds1+ data1$log_MPdist+ data1$prim_other_total+ data1$incumbent+ data1$min_inc_alt)
NPP.2 <- lm(data1$vote_share_t ~ data1$prim_elec+ data1$pres_t_1+ data1$english_percent+ data1$urban+ data1$year2008+ data1$ethfrac+ data1$public_semipublic_p+ data1$dispute_before+ data1$holds1+ data1$log_MPdist+ data1$prim_other_total+ data1$incumbent+ data1$min_inc_alt)
NPP.3 <- lm(data1$vote_share_t_other ~ data1$prim_elec+data1$pres_t_1+ data1$english_percent+ data1$urban+ data1$year2008+ data1$ethfrac+ data1$public_semipublic_p+ data1$dispute_before+ data1$holds1+ data1$log_MPdist+ data1$prim_other_total+ data1$incumbent+ data1$min_inc_alt)
round(summary(NPP.1)$coefficients[2,], digits=4)
round(summary(NPP.2)$coefficients[2,], digits=4)
round(summary(NPP.3)$coefficients[2,], digits=4)


################################################################
## NPP only (ATE)

x<-cbind(data1$pres_t_1, data1$english_percent, data1$urban, data1$year2008, data1$ethfrac, data1$public_semipublic_p, data1$dispute_before, data1$holds1, data1$log_MPdist, data1$prim_other_total, data1$incumbent, data1$min_inc_alt)
mout.1<-Match(Y=data1$winner_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.1.ATE)
mout.2<-Match(Y=data1$vote_share_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.1.ATE)
mout.3<-Match(Y=data1$vote_share_t_other, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.1.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)


################################################################
## NPP only (ATT)

x<-cbind(data1$pres_t_1, data1$english_percent, data1$urban, data1$year2008, data1$ethfrac, data1$public_semipublic_p, data1$dispute_before, data1$holds1, data1$log_MPdist, data1$prim_other_total, data1$incumbent, data1$min_inc_alt)
mout.1<-Match(Y=data1$winner_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.1)
mout.2<-Match(Y=data1$vote_share_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.1)
mout.3<-Match(Y=data1$vote_share_t_other, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.1)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)



###############################################################
## Competitive NPP only (OLS)

CNPP.1 <- lm(data.cnpp$winner_t ~ data.cnpp$prim_elec+data.cnpp$pres_t_1+ data.cnpp$english_percent+ data.cnpp$urban+ data.cnpp$year2008+ data.cnpp$ethfrac+ data.cnpp$public_semipublic_p+ data.cnpp$dispute_before+ data.cnpp$holds1+ data.cnpp$log_MPdist+ data.cnpp$prim_other_total+ data.cnpp$incumbent+ data.cnpp$min_inc_alt)

CNPP.2 <- lm(data.cnpp$vote_share_t ~ data.cnpp$prim_elec+data.cnpp$pres_t_1+ data.cnpp$english_percent+ data.cnpp$urban+ data.cnpp$year2008+ data.cnpp$ethfrac+ data.cnpp$public_semipublic_p+ data.cnpp$dispute_before+ data.cnpp$holds1+ data.cnpp$log_MPdist+ data.cnpp$prim_other_total+ data.cnpp$incumbent+ data.cnpp$min_inc_alt)

CNPP.3 <- lm(data.cnpp$vote_share_t_other ~ data.cnpp$prim_elec+data.cnpp$pres_t_1+ data.cnpp$english_percent+ data.cnpp$urban+ data.cnpp$year2008+ data.cnpp$ethfrac+ data.cnpp$public_semipublic_p+ data.cnpp$dispute_before+ data.cnpp$holds1+ data.cnpp$log_MPdist+ data.cnpp$prim_other_total+ data.cnpp$incumbent+ data.cnpp$min_inc_alt)

round(summary(CNPP.1)$coefficients[2,], digits=4)
round(summary(CNPP.2)$coefficients[2,], digits=4)
round(summary(CNPP.3)$coefficients[2,], digits=4)


###############################################################
## Competitive NPP only (ATE)

x<-cbind(data.cnpp$pres_t_1, data.cnpp$english_percent, data.cnpp$urban, data.cnpp$year2008, data.cnpp$ethfrac, data.cnpp$public_semipublic_p, data.cnpp$dispute_before, data.cnpp$holds1, data.cnpp$log_MPdist, data.cnpp$prim_other_total, data.cnpp$incumbent, data.cnpp$min_inc_alt)

mout.1<-Match(Y=data.cnpp$winner_t, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.cnpp.ATE)
mout.2<-Match(Y=data.cnpp$vote_share_t, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.cnpp.ATE)
mout.3<-Match(Y=data.cnpp$vote_share_t_other, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.cnpp.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)

###############################################################
### Competitive NPP only

x<-cbind(data.cnpp$pres_t_1, data.cnpp$english_percent, data.cnpp$urban, data.cnpp$year2008, data.cnpp$ethfrac, data.cnpp$public_semipublic_p, data.cnpp$dispute_before, data.cnpp$holds1, data.cnpp$log_MPdist, data.cnpp$prim_other_total, data.cnpp$incumbent, data.cnpp$min_inc_alt)
mout.1<-Match(Y=data.cnpp$winner_t, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.cnpp)
mout.2<-Match(Y=data.cnpp$vote_share_t, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.cnpp)
mout.3<-Match(Y=data.cnpp$vote_share_t_other, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.cnpp)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)

################################################################
## Stronghold NPP (OLS)

NNPP.1 <- lm(data.nnpp$winner_t ~ data.nnpp$prim_elec+data.nnpp$pres_t_1+ data.nnpp$english_percent+ data.nnpp$urban+ data.nnpp$year2008+ data.nnpp$ethfrac+ data.nnpp$public_semipublic_p+ data.nnpp$dispute_before+ data.nnpp$holds1+ data.nnpp$log_MPdist+ data.nnpp$prim_other_total+ data.nnpp$incumbent+ data.nnpp$min_inc_alt)
NNPP.2 <- lm(data.nnpp$vote_share_t ~ data.nnpp$prim_elec+data.nnpp$pres_t_1+ data.nnpp$english_percent+ data.nnpp$urban+ data.nnpp$year2008+ data.nnpp$ethfrac+ data.nnpp$public_semipublic_p+ data.nnpp$dispute_before+ data.nnpp$holds1+ data.nnpp$log_MPdist+ data.nnpp$prim_other_total+ data.nnpp$incumbent+ data.nnpp$min_inc_alt)
NNPP.3 <- lm(data.nnpp$vote_share_t_other ~ data.nnpp$prim_elec+data.nnpp$pres_t_1+ data.nnpp$english_percent+ data.nnpp$urban+ data.nnpp$year2008+ data.nnpp$ethfrac+ data.nnpp$public_semipublic_p+ data.nnpp$dispute_before+ data.nnpp$holds1+ data.nnpp$log_MPdist+ data.nnpp$prim_other_total+ data.nnpp$incumbent+ data.nnpp$min_inc_alt)
round(summary(NNPP.1)$coefficients[2,], digits=4)
round(summary(NNPP.2)$coefficients[2,], digits=4)
round(summary(NNPP.3)$coefficients[2,], digits=4)


################################################################
## Stronghold NPP (ATE)

x<-cbind(data.nnpp$pres_t_1, data.nnpp$english_percent, data.nnpp$urban, data.nnpp$year2008, data.nnpp$ethfrac, data.nnpp$public_semipublic_p, data.nnpp$dispute_before, data.nnpp$holds1, data.nnpp$log_MPdist, data.nnpp$prim_other_total, data.nnpp$incumbent, data.nnpp$min_inc_alt)
mout.1<-Match(Y=data.nnpp$winner_t, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.nnpp.ATE)
mout.2<-Match(Y=data.nnpp$vote_share_t, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.nnpp.ATE)
mout.3<-Match(Y=data.nnpp$vote_share_t_other, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.nnpp.ATE)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)


################################################################
## Stronghold NPP (ATT)
x<-cbind(data.nnpp$pres_t_1, data.nnpp$english_percent, data.nnpp$urban, data.nnpp$year2008, data.nnpp$ethfrac, data.nnpp$public_semipublic_p, data.nnpp$dispute_before, data.nnpp$holds1, data.nnpp$log_MPdist, data.nnpp$prim_other_total, data.nnpp$incumbent, data.nnpp$min_inc_alt)

mout.1<-Match(Y=data.nnpp$winner_t, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.nnpp)
mout.2<-Match(Y=data.nnpp$vote_share_t, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.nnpp)
mout.3<-Match(Y=data.nnpp$vote_share_t_other, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.nnpp)

## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)

	
###########################################################################################
###  Table 6 (Panels A and B): Effect on Presidential Elections Results Using Additional Matching Variables
###########################################################################################

rm(list=ls())

library(Matching)
ev.ndc<-c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE)
ev<-c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE)

load("matchingoutput_t56SI.Rdata")


################################################################
## NDC only (OLS)

NDC.1 <- lm(data2$pres_t ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
NDC.2 <- lm(data2$turnout_t_pres ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
round(summary(NDC.1)$coefficients[2,], digits=4)
round(summary(NDC.2)$coefficients[2,], digits=4)

################################################################
## NDC only (ATE)

x<-cbind(data2$pres_t_1, data2$english_percent, data2$urban, data2$year2008, data2$ethfrac, data2$public_semipublic_p, data2$dispute_before, data2$holds1, data2$log_MPdist, data2$prim_other_total, data2$incumbent)
mout.1<-Match(Y=data2$pres_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.2<-Match(Y=data2$turnout_t_pres, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)


################################################################
## NDC only (ATT)
x<-cbind(data2$pres_t_1, data2$english_percent, data2$urban, data2$year2008, data2$ethfrac, data2$public_semipublic_p, data2$dispute_before, data2$holds1, data2$log_MPdist, data2$prim_other_total, data2$incumbent)
mout.1<-Match(Y=data2$pres_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.2<-Match(Y=data2$turnout_t_pres, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)

################################################################
## NPP only (OLS)

NPP.1 <- lm(data1$pres_t ~ data1$prim_elec+data1$pres_t_1+ data1$english_percent+ data1$urban+ data1$year2008+ data1$ethfrac+ data1$public_semipublic_p+ data1$dispute_before+ data1$holds1+ data1$log_MPdist+ data1$prim_other_total+ data1$incumbent+ data1$min_inc_alt)
NPP.2 <- lm(data1$turnout_t_pres ~ data1$prim_elec+data1$pres_t_1+ data1$english_percent+ data1$urban+ data1$year2008+ data1$ethfrac+ data1$public_semipublic_p+ data1$dispute_before+ data1$holds1+ data1$log_MPdist+ data1$prim_other_total+ data1$incumbent+ data1$min_inc_alt)
round(summary(NPP.1)$coefficients[2,], digits=4)
round(summary(NPP.2)$coefficients[2,], digits=4)

################################################################
## NPP only (ATE)

x<-cbind(data1$pres_t_1, data1$english_percent, data1$urban, data1$year2008, data1$ethfrac, data1$public_semipublic_p, data1$dispute_before, data1$holds1, data1$log_MPdist, data1$prim_other_total, data1$incumbent, data1$min_inc_alt)
mout.1<-Match(Y=data1$pres_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.1.ATE)
mout.2<-Match(Y=data1$turnout_t_pres, Tr=data1$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.1.ATE)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)

################################################################
## NPP only (ATT)

x<-cbind(data1$pres_t_1, data1$english_percent, data1$urban, data1$year2008, data1$ethfrac, data1$public_semipublic_p, data1$dispute_before, data1$holds1, data1$log_MPdist, data1$prim_other_total, data1$incumbent, data1$min_inc_alt)
mout.<-Match(Y=data1$pres_t, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.1)
mout.2<-Match(Y=data1$turnout_t_pres, Tr=data1$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.1)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)



###############################################################
## Competitive NPP only (OLS)


CNPP.4 <- lm(data.cnpp$pres_t ~ data.cnpp$prim_elec+data.cnpp$pres_t_1+ data.cnpp$english_percent+ data.cnpp$urban+ data.cnpp$year2008+ data.cnpp$ethfrac+ data.cnpp$public_semipublic_p+ data.cnpp$dispute_before+ data.cnpp$holds1+ data.cnpp$log_MPdist+ data.cnpp$prim_other_total+ data.cnpp$incumbent+ data.cnpp$min_inc_alt)
CNPP.5 <- lm(data.cnpp$turnout_t_pres ~ data.cnpp$prim_elec+data.cnpp$pres_t_1+ data.cnpp$english_percent+ data.cnpp$urban+ data.cnpp$year2008+ data.cnpp$ethfrac+ data.cnpp$public_semipublic_p+ data.cnpp$dispute_before+ data.cnpp$holds1+ data.cnpp$log_MPdist+ data.cnpp$prim_other_total+ data.cnpp$incumbent+ data.cnpp$min_inc_alt)
round(summary(CNPP.1)$coefficients[2,], digits=4)
round(summary(CNPP.2)$coefficients[2,], digits=4)


###############################################################
## Competitive NPP only (ATE)

x<-cbind(data.cnpp$pres_t_1, data.cnpp$english_percent, data.cnpp$urban, data.cnpp$year2008, data.cnpp$ethfrac, data.cnpp$public_semipublic_p, data.cnpp$dispute_before, data.cnpp$holds1, data.cnpp$log_MPdist, data.cnpp$prim_other_total, data.cnpp$incumbent, data.cnpp$min_inc_alt)
mout.1<-Match(Y=data.cnpp$pres_t, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.cnpp.ATE)
mout.2<-Match(Y=data.cnpp$turnout_t_pres, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.cnpp.ATE)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)


###############################################################
### Competitive NPP only

x<-cbind(data.cnpp$pres_t_1, data.cnpp$english_percent, data.cnpp$urban, data.cnpp$year2008, data.cnpp$ethfrac, data.cnpp$public_semipublic_p, data.cnpp$dispute_before, data.cnpp$holds1, data.cnpp$log_MPdist, data.cnpp$prim_other_total, data.cnpp$incumbent, data.cnpp$min_inc_alt)
mout.1<-Match(Y=data.cnpp$pres_t, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.cnpp)
mout.2<-Match(Y=data.cnpp$turnout_t_pres, Tr=data.cnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.cnpp)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)

################################################################
## NPP Stronghold (OLS)

NNPP.4 <- lm(data.nnpp$pres_t ~ data.nnpp$prim_elec+data.nnpp$pres_t_1+ data.nnpp$english_percent+ data.nnpp$urban+ data.nnpp$year2008+ data.nnpp$ethfrac+ data.nnpp$public_semipublic_p+ data.nnpp$dispute_before+ data.nnpp$holds1+ data.nnpp$log_MPdist+ data.nnpp$prim_other_total+ data.nnpp$incumbent+ data.nnpp$min_inc_alt)
NNPP.5 <- lm(data.nnpp$turnout_t_pres ~ data.nnpp$prim_elec+data.nnpp$pres_t_1+ data.nnpp$english_percent+ data.nnpp$urban+ data.nnpp$year2008+ data.nnpp$ethfrac+ data.nnpp$public_semipublic_p+ data.nnpp$dispute_before+ data.nnpp$holds1+ data.nnpp$log_MPdist+ data.nnpp$prim_other_total+ data.nnpp$incumbent+ data.nnpp$min_inc_alt)
round(summary(NNPP.1)$coefficients[2,], digits=4)
round(summary(NNPP.2)$coefficients[2,], digits=4)


################################################################
## NPP Stronghold  (ATE)

x<-cbind(data.nnpp$pres_t_1, data.nnpp$english_percent, data.nnpp$urban, data.nnpp$year2008, data.nnpp$ethfrac, data.nnpp$public_semipublic_p, data.nnpp$dispute_before, data.nnpp$holds1, data.nnpp$log_MPdist, data.nnpp$prim_other_total, data.nnpp$incumbent, data.nnpp$min_inc_alt)
mout.1<-Match(Y=data.nnpp$pres_t, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.nnpp.ATE)
mout.2<-Match(Y=data.nnpp$turnout_t_pres, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATE", exact=ev, Weight.matrix=genout.nnpp.ATE)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)


################################################################
## NPP Stronghold (ATT)

x<-cbind(data.nnpp$pres_t_1, data.nnpp$english_percent, data.nnpp$urban, data.nnpp$year2008, data.nnpp$ethfrac, data.nnpp$public_semipublic_p, data.nnpp$dispute_before, data.nnpp$holds1, data.nnpp$log_MPdist, data.nnpp$prim_other_total, data.nnpp$incumbent, data.nnpp$min_inc_alt)
mout.1<-Match(Y=data.nnpp$pres_t, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.nnpp)
mout.2<-Match(Y=data.nnpp$turnout_t_pres, Tr=data.nnpp$prim_elec, X=x, M=1, estimand="ATT", exact=ev, Weight.matrix=genout.nnpp)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)

###########################################################################################
###  Table 5 (Panel C): Effect on Parliamentary Elections Results Using Additional Matching Variables
###########################################################################################

rm(list=ls())

library(Matching)
ev.ndc<-c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE)

load("matchingoutput_t56SIc.Rdata")

################################################################
## NDC Competitive (OLS)

NDC.1 <- lm(data2$winner_t ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
NDC.2 <- lm(data2$vote_share_t_other ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
NDC.3 <- lm(data2$vote_share_t ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
round(summary(NDC.1)$coefficients[2,], digits=4)
round(summary(NDC.2)$coefficients[2,], digits=4)
round(summary(NDC.3)$coefficients[2,], digits=4)


################################################################
## NDC Competitive (ATE)

x<-cbind(data2$pres_t_1, data2$english_percent, data2$urban, data2$year2008, data2$ethfrac, data2$public_semipublic_p, data2$dispute_before, data2$holds1, data2$log_MPdist, data2$prim_other_total, data2$incumbent)
mout.1<-Match(Y=data2$winner_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.2<-Match(Y=data2$vote_share_t_other, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.3<-Match(Y=data2$vote_share_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)


################################################################
## NDC Competitive (ATT)

x<-cbind(data2$pres_t_1, data2$english_percent, data2$urban, data2$year2008, data2$ethfrac, data2$public_semipublic_p, data2$dispute_before, data2$holds1, data2$log_MPdist, data2$prim_other_total, data2$incumbent)

mout.1<-Match(Y=data2$winner_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.2<-Match(Y=data2$vote_share_t_other, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.3<-Match(Y=data2$vote_share_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)

################################################################
## NDC Stronghold (OLS)

NDC.1 <- lm(data2a$winner_t ~ data2a$prim_elec+data2a$pres_t_1+ data2a$english_percent+ data2a$urban+ data2a$year2008+ data2a$ethfrac+ data2a$public_semipublic_p+ data2a$dispute_before+ data2a$holds1+ data2a$log_MPdist+ data2a$prim_other_total+ data2a$incumbent)
NDC.2 <- lm(data2a$vote_share_t_other ~ data2a$prim_elec+data2a$pres_t_1+ data2a$english_percent+ data2a$urban+ data2a$year2008+ data2a$ethfrac+ data2a$public_semipublic_p+ data2a$dispute_before+ data2a$holds1+ data2a$log_MPdist+ data2a$prim_other_total+ data2a$incumbent)
NDC.3 <- lm(data2a$vote_share_t ~ data2a$prim_elec+data2a$pres_t_1+ data2a$english_percent+ data2a$urban+ data2a$year2008+ data2a$ethfrac+ data2a$public_semipublic_p+ data2a$dispute_before+ data2a$holds1+ data2a$log_MPdist+ data2a$prim_other_total+ data2a$incumbent)
round(summary(NDC.1)$coefficients[2,], digits=4)
round(summary(NDC.2)$coefficients[2,], digits=4)
round(summary(NDC.3)$coefficients[2,], digits=4)


################################################################
## NDC Stronghold (ATE)

x<-cbind(data2a$pres_t_1, data2a$english_percent, data2a$urban, data2a$year2008, data2a$ethfrac, data2a$public_semipublic_p, data2a$dispute_before, data2a$holds1, data2a$log_MPdist, data2a$prim_other_total, data2a$incumbent)
mout.1<-Match(Y=data2a$winner_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
mout.2<-Match(Y=data2a$vote_share_t_other, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
mout.3<-Match(Y=data2a$vote_share_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)

################################################################
## NDC Stronghold (ATT)

x<-cbind(data2a$pres_t_1, data2a$english_percent, data2a$urban, data2a$year2008, data2a$ethfrac, data2a$public_semipublic_p, data2a$dispute_before, data2a$holds1, data2a$log_MPdist, data2a$prim_other_total, data2a$incumbent)
mout.1<-Match(Y=data2a$winner_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
mout.2<-Match(Y=data2a$vote_share_t_other, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
mout.3<-Match(Y=data2a$vote_share_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
## matching estimates with regression adjustment

lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
lm3<-lm(mout.3$mdata$Y~mout.3$mdata$Tr+mout.3$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)
round(summary(lm3)$coefficients[2,], digits=4)

	
###########################################################################################
###  Table 6 (Panel C): Effect on Presidential Elections Results Using Additional Matching Variables
###########################################################################################

rm(list=ls())

library(Matching)
ev.ndc<-c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE)

load("matchingoutput_t56SIc.Rdata")


################################################################
## NDC Competitive (OLS)

NDC.1 <- lm(data2$pres_t ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
NDC.2 <- lm(data2$turnout_t_pres ~ data2$prim_elec+data2$pres_t_1+ data2$english_percent+ data2$urban+ data2$year2008+ data2$ethfrac+ data2$public_semipublic_p+ data2$dispute_before+ data2$holds1+ data2$log_MPdist+ data2$prim_other_total+ data2$incumbent)
round(summary(NDC.1)$coefficients[2,], digits=4)
round(summary(NDC.2)$coefficients[2,], digits=4)

################################################################
## NDC Competitive (ATE)

x<-cbind(data2$pres_t_1, data2$english_percent, data2$urban, data2$year2008, data2$ethfrac, data2$public_semipublic_p, data2$dispute_before, data2$holds1, data2$log_MPdist, data2$prim_other_total, data2$incumbent)
mout.1<-Match(Y=data2$pres_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
mout.2<-Match(Y=data2$turnout_t_pres, Tr=data2$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2.ATE)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)

################################################################
## NDC Competitive (ATT)

x<-cbind(data2$pres_t_1, data2$english_percent, data2$urban, data2$year2008, data2$ethfrac, data2$public_semipublic_p, data2$dispute_before, data2$holds1, data2$log_MPdist, data2$prim_other_total, data2$incumbent)
mout.1<-Match(Y=data2$pres_t, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
mout.2<-Match(Y=data2$turnout_t_pres, Tr=data2$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)

################################################################
## NDC Stronghold (OLS)

NDC.1 <- lm(data2a$pres_t ~ data2a$prim_elec+data2a$pres_t_1+ data2a$english_percent+ data2a$urban+ data2a$year2008+ data2a$ethfrac+ data2a$public_semipublic_p+ data2a$dispute_before+ data2a$holds1+ data2a$log_MPdist+ data2a$prim_other_total+ data2a$incumbent)
NDC.2 <- lm(data2a$turnout_t_pres ~ data2a$prim_elec+data2a$pres_t_1+ data2a$english_percent+ data2a$urban+ data2a$year2008+ data2a$ethfrac+ data2a$public_semipublic_p+ data2a$dispute_before+ data2a$holds1+ data2a$log_MPdist+ data2a$prim_other_total+ data2a$incumbent)
round(summary(NDC.1)$coefficients[2,], digits=4)
round(summary(NDC.2)$coefficients[2,], digits=4)

################################################################
## NDC Stronghold (ATE)

x<-cbind(data2a$pres_t_1, data2a$english_percent, data2a$urban, data2a$year2008, data2a$ethfrac, data2a$public_semipublic_p, data2a$dispute_before, data2a$holds1, data2a$log_MPdist, data2a$prim_other_total, data2a$incumbent)
mout.1<-Match(Y=data2a$pres_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
mout.2<-Match(Y=data2a$turnout_t_pres, Tr=data2a$prim_elec, X=x, M=1, estimand="ATE", exact= ev.ndc, Weight.matrix=genout.2a.ATE)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)


################################################################
## NDC Stronghold (ATT)

x<-cbind(data2a$pres_t_1, data2a$english_percent, data2a$urban, data2a$year2008, data2a$ethfrac, data2a$public_semipublic_p, data2a$dispute_before, data2a$holds1, data2a$log_MPdist, data2a$prim_other_total, data2a$incumbent)
mout.1<-Match(Y=data2a$pres_t, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
mout.2<-Match(Y=data2a$turnout_t_pres, Tr=data2a$prim_elec, X=x, M=1, estimand="ATT", exact= ev.ndc, Weight.matrix=genout.2a)
## matching estimates with regression adjustment
lm1<-lm(mout.1$mdata$Y~mout.1$mdata$Tr+mout.1$mdata$X)
lm2<-lm(mout.2$mdata$Y~mout.2$mdata$Tr+mout.2$mdata$X)
round(summary(lm1)$coefficients[2,], digits=4)
round(summary(lm2)$coefficients[2,], digits=4)





